const router = require('express').Router();

const stubs = {
  ['todo-list']: 'success',
};

router.get('/admin/set/:key/:value', (req, res) => {
  const { key, value } = req.params;
  stubs[key] = value;
  res.send('ok');
});

router.get('/admin', (req, res) => {
  res.send(`
  <ul>

  <li>
    <h3>todo-list</h3>
    <button onclick="fetch('/api/admin/set/todo-list/success')">success</button>
    <button onclick="fetch('/api/admin/set/todo-list/success-more')">more</button>
    <button onclick="fetch('/api/admin/set/todo-list/empty')">empty</button>
    <button onclick="fetch('/api/admin/set/todo-list/error')">error</button>
  </li>

  </ul>
  `);
});

router.get('/todo-list', (req, res) => {
  res
    .status(stubs['todo-list'] === 'error' ? 400 : 200)
    .send(require(`./json/todo-list/${stubs['todo-list']}.json`));
});

router.post('/todo', (req, res) => {
  res.send({});
});

module.exports = router;
